package org.dromara.admin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *  账本记录类型:RENT_INCOME-租金收入，WITHDRAWAL-提现
 */
@Getter
@AllArgsConstructor
public enum AccountBookType {

    /**
     * 租金收入
     */
    RENT_INCOME("RENT_INCOME", "租金收入"),

    /**
     * 提现
     */
    WITHDRAWAL("WITHDRAWAL", "提现");

    /**
     * 存库用的值
     */
    private final String code;

    /**
     * 前端展示用
     */
    private final String info;

    /**
     * 根据 code 获取枚举
     */
    public static AccountBookType getByCode(String code) {
        for (AccountBookType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据 info 获取枚举
     */
    public static AccountBookType getByInfo(String info) {
        for (AccountBookType type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
